package com.Common;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;

public class DataOper {

    /**
     * 将json转化成对象数组  szr
     * @param ent
     * @param params
     * @param <T>
     * @return
     */
    public static <T> List<T> jsonToEntity(T ent, String params) {
        ObjectMapper op = new ObjectMapper();
        List<T>  item=null;
        JavaType jt = op.getTypeFactory().constructParametricType(ArrayList.class, ent.getClass());
        try {
            item = op.readValue(params, jt);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return item;
    }


}
